package com.ruan.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @ClassName:MyLogGateWayFilter
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/6/25 9:05
 **/
@Component
public class MyLogGateWayFilter implements GlobalFilter, Ordered {


    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

//        System.out.println("********************");
//
//       String userName= exchange.getRequest().getQueryParams().getFirst("userName");
//
//        System.out.println("userName："+userName);
//
//       if(userName==null || "".equals(userName.trim())){
//
//           System.out.println("身份非法。。。。");
//
//           exchange.getResponse().setStatusCode(HttpStatus.NOT_FOUND);
//
//           return exchange.getResponse().setComplete();
//
//       }
//
//       return chain.filter(exchange);

//        String token=exchange.getRequest().getQueryParams().getFirst("token");
//
//
//        if(token==null || "".equals(token.trim())){
//
//            System.out.println("请先登录。。。");
//
//            exchange.getResponse().setStatusCode(HttpStatus.NOT_FOUND);
//
//            return exchange.getResponse().setComplete();
//
//        }

        return chain.filter(exchange);

    }

    @Override
    public int getOrder() {
        return 0;
    }
}
